package com.opgea.tutor.domain.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: Subject
 * 
 */
@Entity
@Table(name = "SUBJECT")
public class Subject implements Serializable, Comparable<Subject> {

    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String name;
    @SuppressWarnings("rawtypes")
    @ElementCollection(targetClass = com.opgea.tutor.domain.entities.Specialization.class)
    @CollectionTable(name = "SUBJECT_CATEGORY", joinColumns = { @JoinColumn(name = "SUBJECT_ID") })
    private Collection specializations;

    public Subject() {
	super();
    }

    public int getId() {
	return id;
    }

    public void setId(int id) {
	this.id = id;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    @SuppressWarnings("rawtypes")
    public Collection getSpecializations() {
	return specializations;
    }

    @SuppressWarnings("rawtypes")
    public void setSpecializations(Collection specializations) {
	this.specializations = specializations;
    }

    @Override
    public String toString() {
	return "Subject [id=" + id + ", name=" + name + ", specializations="
		+ specializations + "]";
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + id;
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Subject other = (Subject) obj;
	if (id != other.id)
	    return false;
	return true;
    }

    @Override
    public int compareTo(Subject o) {
	return this.id - o.getId();
    }

}
